package cn.tedu.controller;

import cn.tedu.entity.User;
import cn.tedu.mapper.HttpMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Http2Controller {
    @Autowired
    private HttpMapper mapper;

    @GetMapping("user")
    public String getUserAll() {
        List<User> list = mapper.getUserAll();
        return list.toString();
    }

    //localhost:8080/getUserById?id=1 --> localhost:8080/getUserById/1
    //@PathVariable 表示获取请求路径中参数的值,要求必须同名
    @GetMapping("user/{id}")
    public User getUser(@PathVariable int id) {
        User user = mapper.getUser(id);
        return user;
    }

    @DeleteMapping("user/{id}")
    public String deleteUser(@PathVariable int id) {
        mapper.deleteUser(id);
        return "删除成功!";
    }
}
